﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_EarningToVirtual : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        SecondLevelPassword = true;
        RequestLoginPage = "BalanceCenter/EarningToVirtual.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void btnOK_Click(object sender, EventArgs e)
    {
        double Money = 0;

        if (tbMoney.Text.Trim().Equals(""))
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "请输入您要转帐的金额!");
        }
        else
        {
            Money = ShoveEL._Convert.StrToDouble(tbMoney.Text.Trim(), 0);

            if (Money <= 0)
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "请输入正确的转帐金额!");

                return;
            }
        }

        int ReturnValue = 0;
        string ReturnDescription = "";

        try
        {
            DAL.Procedures.P_EarningToVirtual.Call(_User.ID, tbToName.Text.Trim(), Money, tbRemark.Text,ShoveEL._Convert.StrToInt(ddlChangeType.SelectedValue,0), ref ReturnValue, ref ReturnDescription);

            if (ReturnValue < 0)
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, ReturnDescription);
                return;
            }
            else
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "转帐成功!");

                tbMoney.Text = "";
                tbRemark.Text = "";
            }
        }
        catch { }

        BindData();
    }

    private void BindData()
    {
        lbEarning.Text = "   <font color='red'>" + (_User.Earning - _User.EarningBalanced).ToString() + "</font>";
        lbVirtual.Text = "   <font color='red'>" + _User.VirtualMoney.ToString() + "</font>";

        tbToName.Text = _User.Name;
    }
}
